package com.jmb.apiplatform.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    private Integer code; // 状态码
    private String msg;   // 错误信息
    private Object data;  // 返回的数据(因为不知道返回是什么类型,object返回)

    /**
     *
     * @param data
     * 这个地方改造一下，之前是一个个定义，我觉得太繁琐，修改一下。
     */

    public static Result success(Object data) {
        Result result = new Result();
        result.code=200;
        result.msg="操作成功";
        result.data=data;
        return result;
    }

    public static Result success() {
        Result result = new Result();
        result.code=200;
        result.msg="操作成功";
        result.data=new HashMap<>();
        return result;
    }

    public static Result success(String msg) {
        Result result = new Result();
        result.code=200;
        result.msg=msg;
        result.data=new HashMap<>();
        return result;
    }

    public static Result success(String msg, Object data) {
        Result result = new Result();
        result.code=200;
        result.msg=msg;
        result.data=data;
        return result;
    }

    public static Result fail() {
        Result result = new Result();
        result.code=500;
        result.msg="操作失败";
        result.data=new HashMap<>();
        return result;
    }

    public static Result fail(String msg) {
        Result result = new Result();
        result.code=500;
        result.msg=msg;
        result.data=new HashMap<>();
        return result;
    }

    public static Result fail(int code, String msg) {
        Result result = new Result();
        result.code=code;
        result.msg=msg;
        result.data=new HashMap<>();
        return result;
    }
    public static Result failCode(String msg) {
        Result result = new Result();
        result.code=401;
        result.msg=msg;
        result.data=new HashMap<>();
        return result;
    }
}
